import { BorrowBookState } from '@/pages/borrowBook/interface';
import request from './index';

export interface Pager {
    page: number;
    limit: number;
}

export interface FetchListFilterParams {
    order_no: string;
    rfid: string;
    isbn: string;
    book_name: string;
    username: string;
    cate_id: string;
    create_time: string;
    finish_time: string;
}

export type FetchListParams = Pager & Partial<FetchListFilterParams>;

export function fetchBorrowBookList(
    params: FetchListParams,
): Promise<RDD<{ total: number; data: BorrowBookState[] }>> {
    return request.post('/getBookRentRecord', {
        data: {
            status: 1,
            ...params,
        },
    });
}

interface Catelog {
    id: string;
    cate_name: string;
}

export function fetchBookCatelog(): Promise<RDD<Catelog[]>> {
    return request.post('/getCateInfo', {
        data: {
            encode: true,
        },
    });
}

export function fetchBorrowBookDetails(data: { rent_id: string }): Promise<RD> {
    return request.post('/getRentBookDetail', {
        data: {
            rent_id: data.rent_id,
        },
    });
}
